home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / mactool / thinkcgu.sit / TC Prog Guide / card_62691.txt < prev    next >
Encoding:
Text File  |  1991-02-27  |  3.0 KB  |  125 lines

  1. -- card: 62691 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 00
  10. -- high flags: 0007
  11. -- rect: left=30 top=78 right=296 bottom=478
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 4
  16. -- text size: 9
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: 
  20.  
  21.  
  22. -- part contents for card part 1
  23. ----- text -----
  24. /*
  25. *   FILE:    class.c
  26. *   AUTHOR:  R.G.
  27. *   CREATED: August 4, 1990
  28. *   
  29. *   Defines root class methods as well as the new_init(), and
  30. *   destroy_delete() functions replacing new() and delete().
  31. */
  32.  
  33. # include   "class.h"
  34. # include   <stdlib.h>
  35. # include   <oops.h>
  36.  
  37. /******************************************************************
  38. *   Generic class initialization
  39. ******************************************************************/
  40. boolean   Generic_Class::init(void)
  41. {
  42.     return TRUE;
  43. }
  44.  
  45. /******************************************************************
  46. *   Generic class termination
  47. ******************************************************************/
  48. boolean   Generic_Class::destroy(void)
  49. {
  50.     return TRUE;
  51. }
  52.  
  53. /******************************************************************
  54. *   Function to simulate automated initialization.  Returns FALSE if
  55. *   unable to 'new' OR if init method fails.  In the latter case, the
  56. *   object is 'deleted' without being destroyed, since it is assumed
  57. *   that a failing init method will deallocate any space it has 
  58. *   allocated itself.  The programmer must enforce this for all
  59. *   his/her classes.
  60. *
  61. *   IMPORTANT: This function does not work in C++.  It is only in
  62. *   Think C that a class name may be considered a void pointer and
  63. *   may be passed as an argument to a function.  See the comment
  64. *   in the header file.
  65. ******************************************************************/
  66. void   *new_init(void *cclass)    
  67. /*  note: class names are void pointers in TC
  68. */
  69. {
  70.     Generic_Class   *object;
  71.  
  72. # ifdef   INDIRECT
  73.     object = new(cclass);
  74. # else
  75.     object = malloc((size_t) (*(int *) cclass));
  76. /*  class size is stored in first two bytes of cclass; this gets it!
  77. */ 
  78.     blessD(object,cclass);
  79. # endif
  80.  
  81.     if (object == NULL)
  82.         return NULL;
  83.     else
  84.     {
  85.         if (!object->init())
  86.         {
  87. # ifdef   INDIRECT
  88.             delete(object);
  89. # else
  90.             free(object);
  91. # endif
  92.             return NULL;
  93.         }
  94.         else
  95.             return object;
  96.     }
  97. }
  98.  
  99. /******************************************************************
  100. *   Function to simulate automated deallocation.  Object must have
  101. *   been allocated and init'ed already.
  102. ******************************************************************/
  103. void   destroy_delete(Generic_Class *object)
  104. {
  105.     object->destroy();
  106. # ifdef   INDIRECT
  107.     delete(object);
  108. # else
  109.     free(object);
  110. # endif
  111. }
  112.  
  113.  
  114.  
  115. -- part contents for background part 7
  116. ----- text -----
  117. 211
  118.  
  119. -- part contents for background part 4
  120. ----- text -----
  121. File 2 of 2:
  122.  
  123. -- part contents for background part 17
  124. ----- text -----
  125. p3